﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XMK.Tadong.Biz;
using XMK.Tadong.Model;
using XMK.Tadong.Web.Language;
using Newtonsoft.Json;
using System.Data;

namespace XMK.Tadong.Web.Views.DataSearch
{
    public partial class WatchViewHander : FileExplorerPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string file_id = this.Request.QueryString["id"].ToString();
            string FileSpace_Type = this.Request.QueryString["space_type"].ToString();
            string File_Name=null;//文件名
 
            EXTBiz extbiz = new EXTBiz();
            ExtTypeinfo extcode = null;
            if (FileSpace_Type.Equals("10"))
            {
                TB_PERSON_FILEInfo model = new TB_PERSON_FILEInfo();
                TB_PERSON_FILEBiz bll = new TB_PERSON_FILEBiz();
                model = bll.GetFileInfoById(file_id);
                extcode = extbiz.getExtCodeByExtent(model.FILE_EXT);
                File_Name = model.FILE_NAME;
            }
            if (FileSpace_Type.Equals("20"))
            {
                TB_TEAM_FILEInfo model = new TB_TEAM_FILEInfo();
                TB_TEAM_FILEBiz bll = new TB_TEAM_FILEBiz();
                model = bll.GetTeamFile(file_id);
                extcode = extbiz.getExtCodeByExtent(model.FILE_EXT);
                File_Name = model.FILE_NAME;
            }
            else if (FileSpace_Type.Equals("30"))
            {
                TB_XMK_FILEInfo model = new TB_XMK_FILEInfo();
                Tb_Xmk_FileBiz bll = new Tb_Xmk_FileBiz();
                model = bll.QueryById(file_id);
                extcode = extbiz.getExtCodeByExtent(model.FILE_EXT);
                File_Name = model.FILE_NAME;
            }

            if (extcode != null)
            {
                string user_id = LoginUserBiz.LoginUserID();
                Base_RM_UserInfoBiz userbiz = new Base_RM_UserInfoBiz();
                Base_UserInfo usermodel = userbiz.GetUserModelByID(user_id);
                string language = usermodel.USER_LANG == 1 ? "CN" : "EN";
                string returnStr;
                if (extcode.EXT_URL.Contains("?"))
                {
                    returnStr = extcode.EXT_URL + "&id=" + file_id + "&space_type=" + FileSpace_Type + "&File_Name=" + File_Name + "&language=" + language + "&USER_ACCOUNT=" + usermodel.USER_ACCOUNT + "&USERPWD=" + usermodel.USER_PWD;
                }
                else
                {
                    returnStr = extcode.EXT_URL + "?id=" + file_id + "&space_type=" + FileSpace_Type + "&File_Name=" + File_Name + "&language=" + language + "&USER_ACCOUNT=" + usermodel.USER_ACCOUNT + "&USERPWD=" + usermodel.USER_PWD;
                }

                Response.Redirect(returnStr);



                //string resultJson = returnStr;
                //DataTable dt = new DataTable();
                //dt.Columns.Add("url", Type.GetType("System.String")); //url
                //DataRow newRow1 = dt.NewRow();
                //newRow1["url"] = returnStr;
                //dt.Rows.Add(newRow1);
                //resultJson = XMK.Utils.JsonHelper.ToJson(dt);
                //Response.ContentType = "text/json";
                //Response.Write(resultJson);
                //Response.End();
                
                
            }
            else
            {
                Response.Redirect("WatchUnkownView.aspx?id=" + file_id + "&space_type=" + FileSpace_Type);
            }

        }
    }
}